package com.lyc.service.impl;

import com.lyc.mapper.LkMapper;
import com.lyc.pojo.Like;
import com.lyc.pojo.Result;
import com.lyc.service.LkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LkServiceImpl implements LkService {
    @Autowired
    private LkMapper lkMapper;

    // 获取用户对某个帖子的所有互动（点赞和收藏）
    @Override
    public List<Like> getLkId(Integer userId, Integer postId) {
        return lkMapper.getLkId(userId, postId);

    }

    // 添加点赞
    @Override
    public Result addLike(Like like) {
        Integer userId = like.getUserId();
        Integer postId = like.getPostId();
        String type = like.getType();
        lkMapper.addLike(userId, postId, type);
        return Result.success("点赞成功");
    }

    // 添加收藏
    @Override
    public Result addFavorite(Like like) {
        Integer userId = like.getUserId();
        Integer postId = like.getPostId();
        String type = like.getType();
        lkMapper.addFavorite(userId, postId, type);
        return Result.success("收藏成功");
    }

    // 获取用户点赞列表
    @Override
    public List<Like> getUserLkList(Integer userId, String type) {
        return lkMapper.getUserLkList(userId, type);
    }

    // 获取用户收藏列表
    @Override
    public List<Like> getUserFavorites(Integer userId, String type) {
        return lkMapper.getUserLkList(userId, type);
    }

    //判断当前用户是否点赞
    @Override
    public Boolean isLiked(Integer userId, Integer postId) {
        Like like = lkMapper.isLiked(userId, postId);
        return like != null;
    }

    //判断当前用户是否收藏
    @Override
    public Boolean isFavorite(Integer userId, Integer postId) {
        Like like = lkMapper.isFavorite(userId, postId);
        return like != null;
    }

    // 获取作者
    @Override
    public String getAuthor(Integer userId) {
        return lkMapper.getAuthor(userId);
    }

    // 获取帖子点赞总数
    @Override
    public Integer getLikeCount(Integer postId) {
        return lkMapper.getLikeCount(postId);
    }

    // 获取帖子收藏总数
    @Override
    public Integer getFavoriteCount(Integer postId) {
        return lkMapper.getFavoriteCount(postId);
    }

    //取消点赞
    @Override
    public void removeLike(Integer lkId) {
        lkMapper.removeLkList(lkId);
    }
    // 取消收藏
    @Override
    public void removeFavorite(Integer lkId) {
        lkMapper.removeLkList(lkId);
    }



}